<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var str1 = "abcdefg";
      var str2 = "你好世界王清照";
      function reverse_str(str) {
        var arr = str.split("").reverse();
        // var newstr = [];
        // for (var i = 0; i < arr.length; i++) newstr += arr[i];//第一种
        var newstr = arr.join(""); //第二种
        return newstr;
      }
      console.log(reverse_str(str1));
      console.log(reverse_str(str2));
    </script>
  </body>
</html>
